<?php

include_once('datos/ClienteDAL.php');
include_once('entities/Cliente.php');

$page = $_GET['page'];
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];

if (!$sidx)
    $sidx = 1;

$cliente = new ClienteDAL();

$lista = $cliente->obtenerCliente();
$count = count($lista);

if ($count > 0 && $limit > 0) {
    $total_pages = ceil($count / $limit);
} else {
    $total_pages = 0;
}

if ($page > $total_pages)
    $page = $total_pages;

$start = $limit * $page - $limit;

if ($start < 0)
    $start = 0;

header("Content-type: text/xml;charset=utf-8");

$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .= "<rows>";
$s .= "<page>" . $page . "</page>";
$s .= "<total>" . $total_pages . "</total>";
$s .= "<records>" . $count . "</records>";

foreach ($lista as $value) {

    $s .= "<row id='" . $value->getApellido() . "'>";
    $s .= "<cell>" . $value->getApellido() . "</cell>";
    $s .= "<cell>" . $value->getFechaNacimiento() . "</cell>";
    $s .= "<cell>" . $value->getIdTipoDocumento() . "</cell>";
    $s .= "<cell>" . $value->getNumeroDocumento() . "</cell>";
    $s .= "<cell>" . $value->getCalle() . "</cell>";
    $s .= "<cell>" . $value->getNumero() . "</cell>";
    $s .= "<cell>" . $value->getDepto() . "</cell>";
    $s .= "<cell>" . $value->getPiso() . "</cell>";
    $s .= "<cell>" . $value->getIdLocalidad() . "</cell>";
    $s .= "<cell>" . $value->getIdProvincia() . "</cell>";
    $s .= "<cell>" . $value->getCodigoPostal() . "</cell>";
    $s .= "<cell>" . $value->getCodigoPostalManual() . "</cell>";
    $s .= "<cell>" . $value->getTelefono() . "</cell>";
    $s .= "<cell>" . $value->getTelefono2() . "</cell>";
    $s .= "<cell>" . $value->getEmail() . "</cell>";
    $s .= "<cell>" . $value->getEmail2() . "</cell>";
    $s .= "<cell>" . $value->getIsActivo() . "</cell>";
    $s .= "<cell>" . $value->getIsBorrado() . "</cell>";

    
    
    $s .= "</row>";
}

$s .= "</rows>";

echo $s;
?>

